from aiogram import types
from aiogram_dialog import DialogManager
from fluentogram import TranslatorRunner

from src.application.user.service import UserService


async def add_ip_address(message: types.Message, _, manager: DialogManager, ip_address: str = None):
    locale: TranslatorRunner = manager.middleware_data.get("locale")
    user_service: UserService = manager.middleware_data.get("user_service")

    await user_service.create_allowed_ip(tg_user_id=message.from_user.id, ip_address=ip_address)
    await manager.done()
